package com.cff.shorturl.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3p0DbManager extends DbManager {
	private static ComboPooledDataSource dataSource=null;


	protected C3p0DbManager() {
		try {
			dataSource = new ComboPooledDataSource();
			dataSource.setDriverClass(properties.getProperty("driverClassName"));//设置连接池连接数据库所需的驱动
			dataSource.setJdbcUrl(properties.getProperty("url"));//设置连接数据库的URL	
			dataSource.setUser(properties.getProperty("username"));//设置连接数据库的用户名		
			dataSource.setPassword(properties.getProperty("password"));//设置连接数据库的密码		
			dataSource.setMaxPoolSize(Integer.parseInt(properties.getProperty("maxActive")));//设置连接池的最大连接数		
			dataSource.setMinPoolSize(Integer.parseInt(properties.getProperty("testWhileIdle")));//设置连接池的最小连接数		
			dataSource.setInitialPoolSize(Integer.parseInt(properties.getProperty("initialSize")));//设置连接池的初始连接数		
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public Connection getConnection() throws SQLException {
		return dataSource.getConnection();
	}

}
